package com.ccys.db.service.impl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ccys.common.annotations.LogAnalysisAnnexTag;
import com.ccys.common.util.Kit;
import com.ccys.db.cache.SysCodeUtil;
import com.ccys.db.entity.SysCode;
import com.ccys.db.entity.TblAuditTrail;
import com.ccys.db.mapper.SysCodeMapper;
import com.ccys.db.mapper.TblAuditTrailMapper;
import com.ccys.db.rely.service.impl.BaseServiceImpl;
import com.ccys.db.service.BaseSysCodeService;
import com.ccys.db.service.BaseTblAuditTrailWebService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.Table;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;



@Service
@Slf4j
public class BaseSysCodeServiceImpl extends BaseServiceImpl<SysCode> implements BaseSysCodeService {

    @Autowired(required = false)
    private SysCodeMapper sysCodeMapper;


    @Override
    public String getCodeValue(String name,String catId) {
        if(StringUtils.isEmpty(name)) {
            return null;
        }
        String value = null;
        SysCode code = SysCodeUtil.getCode(name,catId);
        if(code == null){
            List<String> whereList = new ArrayList<>();
            if(StringUtils.isNotEmpty(name)) {
                whereList.add("name = '"+name+"'");
            }
            if(StringUtils.isNotEmpty(catId)) {
                whereList.add("cat_id = '"+catId+"'");
            }
            List<SysCode> codes = this.findListByLimit(SysCode.class, whereList, null);
            if(codes != null && !codes.isEmpty()) {
                code = codes.get(0);
                value = code.getValue();
            }
        }else {
            value = code.getValue();
        }
        return value;
    }
}